
package com.onlyxiahui.ability.basic.common.step;

/**
 * Description <br>
 * Date 2021-05-12 16:09:34<br>
 * 
 * @author XiaHui [onlovexiahui@qq.com]<br>
 * @since 1.0.0
 */

public class NextAsynStep<P, N> {

	private NextAsynRun<P, N> run;
	private NextAsynStep<N, ?> next;

	@SuppressWarnings("unchecked")
	public <V> NextAsynStep<N, V> add(NextAsynRun<P, N> run) {
		this.run = run;
		next = new NextAsynStep<>();
		return (NextAsynStep<N, V>) next;
	}

	public void run(P p) {
		if (null != run && null != next) {
			run.execute(p, (n) -> {
				next.run(n);
			});
		}
	}

	public static <P, N> NextAsynStep<P, N> build() {
		return new NextAsynStep<>();
	}
}
